package com.lcxw.hxzbapi.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcxw.hxzbapi.dao.mapper.RealNameAuthMapper;
import com.lcxw.hxzbapi.entity.pojo.RealNameAuth;
import com.lcxw.hxzbcommon.common.StringUtil;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RealNameAuthService {

    @Resource
    RealNameAuthMapper realNameAuthMapper;

    public int insert(RealNameAuth realNameAuth) {
        return realNameAuthMapper.insert(realNameAuth);
    }

    public RealNameAuth selectById(Integer id) {
        return realNameAuthMapper.selectById(id);
    }

    public RealNameAuth selectByUserId(long userId) {
        QueryWrapper<RealNameAuth> wrapper = new QueryWrapper<>();
        wrapper.eq("userId", userId);
        return realNameAuthMapper.selectOne(wrapper);
    }

    public int update(RealNameAuth realNameAuth) {
        return realNameAuthMapper.updateById(realNameAuth);
    }

    public IPage<RealNameAuth> selectListByStatus(String status, int pageNum, int pageSize) {
        if (StringUtil.isEmpty(status)) {
            status = null;
        }
        IPage<RealNameAuth> iPage = new Page<>(pageNum, pageSize);
        QueryWrapper<RealNameAuth> realNameAuthQueryWrapper = new QueryWrapper<>();
        realNameAuthQueryWrapper.lambda().eq(status != null, RealNameAuth::getStatus, status);
        return realNameAuthMapper
            .selectPage(iPage, realNameAuthQueryWrapper);
    }
}
